package com.ijunfu.thread._03_implements_callable;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 *
 * @title  : 创建线程的第三种方式：实现Callable接口
 * @author : ijunfu <ijunfu@163.com>
 * @date   : 2023/10/23 13:25
 * @version: 1.0
 * @motto  : 位来可期 - 世界很大，我想看看
 *
 */
@Slf4j
public class Main {

    public static void main(String[] args) throws Exception {
        FutureTask<String> futureTask = new FutureTask<>(new MyCallable());

        Thread t = new Thread(futureTask);
        t.start();

        String ret = futureTask.get();
        log.info("ret={}", ret);
    }
}

@Slf4j
class MyCallable implements Callable<String> {

    @Override
    public String call() throws Exception {
        log.info("my callable running...");
        return "Success";
    }
}
